<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<div class="block">
    <div class="block_head">
        <div class="bheadl"></div>
        <div class="bheadr"></div>
        
        <h2>Manage Buildings</h2>
        
        <ul>
            <li>
                <html:link action="/admin/building.do?action=selectLand" >
                    Add Building
                </html:link>
            </li>
        </ul>
    </div>
    <!-- .block_head ends -->

    
    <div class="block_content clearfix">
        <logic:notEmpty name="errorMessages" >
            <div class="message errormsg">
                <logic:iterate id="message" name="errorMessages">
                    <p><bean:write name="message"/></p>
                </logic:iterate>
            </div>
        </logic:notEmpty>
        <logic:notEmpty name="successMessages" >
            <div class="message success">
                <logic:iterate id="message" name="successMessages">
                    <p><bean:write name="message"/></p>
                </logic:iterate>
            </div>
        </logic:notEmpty>
        <fieldset id="filters" class="wide">
            <legend>Filters</legend>
            <html:form action="/admin/buildingListing" method="get">
                <ul class="h100">
                    <li class="search_item">
                        <label>ID</label>
                        <div class="clear"></div>
                        <html:text property="id" styleClass="text tiny"/>
                    </li>
                    <li class="search_item">
                        <label>Building Name</label>
                        <div class="clear"></div>
                        <html:text property="name" styleClass="text small"/>
                    </li>
                    <li class="search_item">
                        <label>Land ID</label>
                        <div class="clear"></div>
                        <html:text property="land" styleClass="text tiny"/>
                    </li>
                    <li class="search_item">
                        <label>Building Type</label>
                        <div class="clear"></div>
                        <html:select property="type" styleClass="chzn-select">
                            <option value=""> -- All -- </option>
                            <logic:iterate id="type" name="buildingTypeList">
                                <html:option value="${type.buildingTypeID}">${type.buildingTypeName}</html:option>
                            </logic:iterate>
                        </html:select>
                    </li>
                    <li class="search_item">
                        <label>No. Floors</label>
                        <div class="clear"></div>
                        <div class="range">
                            <label>From</label> <html:text property="floorF" styleClass="text tiny"/>
                            <div class="clear"></div>
                            <label>To</label> <html:text property="floorT" styleClass="text tiny"/>
                        </div>
                    </li>
                    <li class="search_item">
                        <label>No. Rooms</label>
                        <div class="clear"></div>
                        <div class="range">
                            <label>From</label> <html:text property="roomF" styleClass="text tiny"/>
                            <div class="clear"></div>
                            <label>To</label> <html:text property="roomT" styleClass="text tiny"/>
                        </div>
                    </li>
                    <li class="search_item">
                        <label>Constructed On</label>
                        <div class="clear"></div>
                        <div class="range">
                            <label>From</label> <html:text property="dateF" styleClass="text date_picker small"/>
                            <div class="clear"></div>
                            <label>To</label> <html:text property="dateT" styleClass="text date_picker small"/>
                        </div>
                    </li>
                    <li class="search_item">
                        <label>Status</label>
                        <div class="clear"></div>
                        <html:select property="status" styleClass="chzn-select">
                            <option value=""> -- All -- </option>
                            <logic:iterate id="status" name="statusList">
                                <html:option value="${status[0]}">${status[1]}</html:option>
                            </logic:iterate>
                        </html:select>
                    </li>
                    <li class="search_item">
                        <label>&nbsp;</label>
                        <div class="clear"></div>
                        <div class="range">
                            <input type="submit" class="submit small" value="Filter">
                            <div class="clear"></div>
                            <html:link action="/admin/buildingListing.do" styleClass="submit small gray">Refresh</html:link>
                        </div>
                    </li>
                </ul>
            </html:form>
        </fieldset>
        <html:form styleClass="action_form" action="admin/buildingListing.do" method="post">
            <table cellpadding="0" cellspacing="0" width="100%" class="sortable">
                
                <thead>
                    <tr>
                        <td width="5"><input type="checkbox" class="check_all"/></td>
                        <th>ID #</th>
                        <th>Building Name</th>
                        <th>Land ID</th>
                        <th>Building Type</th>
                        <th>No. Floors</th>
                        <th>No. Rooms</th>
                        <th>Constructed On</th>
                        <th>Status</th>
                        <td width="130">&nbsp;</td>
                    </tr>
                </thead>
                
                <tbody>
                    <logic:empty name="buildingList">
                        <tr>
                            <td class="align-center" colspan="10">There are no buildings</td>
                        </tr>
                    </logic:empty>
                    <logic:notEmpty name="buildingList">
                        <logic:iterate id="building" name="buildingList">
                            <tr>
                                <td>
                                    <html:checkbox property="buildingIDs" value="${building.buildingID}"/>
                                </td>
                                <td>     
                                    <html:link action="/admin/building.do" paramId="buildingID" paramName="building" paramProperty="buildingID">
                                        <bean:write name="building" property="buildingID"/>
                                    </html:link>
                                </td>
                                <td>     
                                    <html:link action="/admin/building.do" paramId="buildingID" paramName="building" paramProperty="buildingID">
                                        <bean:write name="building" property="buildingName"/>
                                    </html:link>
                                </td>
                                <td>     
                                    <bean:write name="building" property="landID"/>
                                </td>
                                <td>     
                                    <bean:write name="building" property="typeName"/>
                                </td>
                                <td>
                                    <bean:write name="building" property="numFloors"/>
                                </td>
                                <td>
                                    <bean:write name="building" property="numRooms"/>
                                </td>
                                <td>
                                    <fmt:formatDate type="date" value="${building.constructedDate}"/>
                                </td>
                                <td>
                                    <bean:write name="building" property="statusName"/>
                                </td>
                                <td class="delete">
                                    <html:link action="/admin/building.do?action=edit" paramId="buildingID" paramName="building" paramProperty="buildingID">
                                        Edit
                                    </html:link>
                                    <html:link styleClass="confirm-button" action="/admin/buildingListing.do?action=delete" paramId="buildingID" paramName="building" paramProperty="buildingID">
                                        Delete
                                    </html:link>
                                </td>
                            </tr>
                        </logic:iterate>
                    </logic:notEmpty>
                </tbody>
                
            </table>
            
            
            <div class="tableactions">
                <html:select styleClass="action_select" property="action">
                    <option value="">Actions</option>
                    <html:option value="deleteBuildings">Delete</html:option>
                </html:select>
                <html:submit styleClass="action_submit submit tiny" value="Apply to selected"/>
            </div>
            <!-- .tableactions ends -->

            <logic:notEmpty name="pagination">
                <div class="pagination right">
                    ${pagination}
                </div>
                <!-- .pagination ends -->
            </logic:notEmpty>

        </html:form>
    </div>
    <!-- .block_content ends -->
    
    <div class="bendl"></div>
    <div class="bendr"></div>
</div>
<!-- .block ends -->